package com.androidified.personalshopper.client;

import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import com.androidified.personalshopper.Constants;
import com.androidified.personalshopper.bean.Commerce;
import com.androidified.personalshopper.bean.PromotionsResponse;

public class PromotionService {

	public static PromotionsResponse get(String api_key, String token, Commerce commerce) {
		String url = Constants.BASE_URL + Constants.PATH + "/{api_key}/{token}/operations/commerce/{id_commerce}/promotion/list/objects";
		
		// Create a new RestTemplate instance
		RestTemplate restTemplate = new RestTemplate();

		// Add the String message converter
		restTemplate.getMessageConverters().add(new GsonHttpMessageConverter());

		// Make the HTTP GET request, marshaling the response to a String
		String id_commerce = commerce.getId();
		PromotionsResponse promo = restTemplate.getForObject(url, PromotionsResponse.class, api_key, token, id_commerce);
		return promo;
	}
}
